﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace LeanEngine.Extensions
{
    /// <summary>
    /// Extension methods for the data type System.Enum.
    /// </summary>
    public static class EnumExtensions
    {
        /// <summary>
        /// Converts to Int32 according to the number format of culture set in the thread.
        /// </summary>
        /// <exception cref="System.ArgumentNullException"></exception>
        /// <exception cref="System.ArgumentException"></exception>
        /// <exception cref="System.FormatException"></exception>
        /// <param name="value">The value to be converted.</param>
        public static int ToInt32(this Enum value)
        {
            return GetValue(value).ToInt32(CultureInfo.CurrentCulture);
        }

        /// <summary>
        /// Converts the specified value of a specified enumerated type to its equivalent string
        /// </summary>
        /// <exception cref="System.ArgumentNullException"></exception>
        /// <exception cref="System.ArgumentException"></exception>
        /// <exception cref="System.FormatException"></exception>
        /// <param name="value">The value to be converted.</param>
        public static string GetValue(this Enum value)
        {
            return Enum.Format(value.GetType(), value, "d");
        }
    }
}